package com.letoken.platform.repo.ecommerce.dao;

import com.letoken.platform.repo.ecommerce.po.EcommerceProductSku;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.letoken.platform.repo.ecommerce.vo.MsgSkuRes;
import com.letoken.platform.repo.mall.po.AppBalanceWallet;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商品库存 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2023-09-08
 */
public interface EcommerceProductSkuMapper extends BaseMapper<EcommerceProductSku> {

    @Select("SELECT * FROM ecommerce_product_sku WHERE product_id = #{productId} and delete_status = 0  order by price asc limit 1")
    EcommerceProductSku defaultSpecification(@Param("productId") Integer productId);


    @Select("SELECT s.id,s.product_id  productId, s.price, s.stock,s.sp_data spData ,p.pic FROM  product p inner join product_sku s on p.id = s.product_id WHERE s.product_id = #{productId} ")
    List<MsgSkuRes> productSkuInfo(@Param("productId")Integer productId);


    @Select("select * from ecommerce_product_sku where id = #{id} for update")
    EcommerceProductSku selectForUpdate(@Param("id") Integer id);



    @Select("select product_id ,sum(sale) as sale  from ecommerce_product_sku eps group by product_id ")
    List<EcommerceProductSku> overviewSale();

}
